
import {
  getOptionTree,
} from "@/api/system/dict";
import {listToMap} from '@/util/util'
import { addedServicesTypeList, addedServicesTypeMap } from '@/const'

const addedServices = {
  state: {
    addedServicesTypeList: addedServicesTypeList,
    addedServicesTypeMap: addedServicesTypeMap
  },
  actions: {
    getAddedServicesTypeList({ state, commit }) {
      return new Promise((resolve, reject) => {
        getOptionTree({ code: 'added_service' }).then(res => {
          const data = (res.data.data || []).map(item => {
            return {
              ...item,
              value: item.dictKey,
              label: item.dictValue,
            }
          })
          commit('TO_MAP', data)
          resolve();
        }).catch(error => {
          reject(error)
        })
      })
    },
  },
  mutations: {
    TO_MAP(state, payload) {
      state.addedServicesTypeList = payload
      state.addedServicesTypeMap = listToMap(state.addedServicesTypeList)
    }
  }

};

export default addedServices;